// 引入样式
import "../../assets/css/normalize.less";
import "../../assets/css/reset.less";
import "../../assets/css/property.less";
import "../../assets/css/basic.less";

import "./run.less";

import { $ } from "../../utils/dom";

import { showBottomNav, showTopNav } from "../../utils/nav";

import { getExerciseReq } from "../../api/course";

/**
 * 顶部导航
 */
showTopNav("sportrun");

/**
 * 导航栏
 */

showBottomNav("sport");

/**
 * 获取运动数据
 */

const getExercise = async () => {
	let res = await getExerciseReq();
	let { errno, data } = res.data;
	if (errno === 0) {
		// console.log(res.data);
		$("#number").textContent = data.sum7Meter;
	}
};

getExercise();

/**
 * 点击GO开始跑步
 */

$("#GOBtn").addEventListener("click", () => {
	$("#mask").classList.add("dpflex");
});

/**
 * 倒计时
 */

let time = 4;
setInterval(() => {
	--time;
	if (time > 0) {
		$("#mask").textContent = time;
	} else if (time === 0) {
		$("#mask").textContent = "GO";
	} else {
		location.href = "./running.html";
	}
}, 3000);
